home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3212 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  81 lines

  1. Newsgroups: comp.lang.c
  2. Path: uu4news.netcom.com!zodiac!szh
  3. From: szh@zcon.com (Syed Zaeem Hosain)
  4. Subject: Re: Clearing the keyboard
  5. Message-ID: <1996Jan26.232559.11147@zcon.com>
  6. Sender: szh@zcon.com (Syed Zaeem Hosain)
  7. Nntp-Posting-Host: zodiac
  8. Reply-To: szh@zcon.com
  9. Organization: Z Consulting Group
  10. References: <4e7amq$nhd@mercury.IntNet.net>
  11. Date: Fri, 26 Jan 1996 23:25:59 GMT
  12.  
  13. In article <4e7amq$nhd@mercury.IntNet.net>, jtomich@IntNet.net (Jeff Tomich) writes:
  14. >: > Huh? Once the buffer is caught up, it shouldn't continue, but you
  15. >: > might want to try fflush(stdin); just the same. ...
  16. >
  17. >: Why?  Are there any other pieces of undefined behavior that you think
  18. >: people "might want to try?"  Nor does the C language defines what
  19. >: happens if you discharge a shotgun at your computer;  maybe you "might
  20. >: want to try" that, also.
  21. >:                                                                
  22. >
  23. >Why not this;
  24. >
  25. >while(kbhit())
  26. >   getch();
  27. >
  28. >this should clear the keyboard...
  29.  
  30. Really? There ain't no such thing in my Sun system! Check out the
  31. following:
  32.  
  33. zodiac{2057}szh: grep -i kbhit /usr/include/*.h
  34. zodiac{2058}szh: grep -i getch /usr/include/*.h
  35. /usr/include/curses.h:# define  getch()         VOID(wgetch(stdscr))
  36. /usr/include/curses.h:#define   mvwgetch(win,y,x)       VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
  37. /usr/include/curses.h:#define   mvgetch(y,x)            mvwgetch(stdscr,y,x)
  38. /usr/include/stdio.h:#define    getchar()       getc(stdin)
  39. zodiac{2059}szh: cat foo.c
  40. #include <curses.h>
  41. #include <stdio.h>
  42.  
  43. int main ()
  44. {
  45.   while (kbhit() )
  46.     getch();
  47.   return(0);
  48. }
  49. zodiac{2060}szh: gcc -o foo foo.c
  50. collect2: ld returned 2 exit status
  51. ld: Undefined symbol 
  52.    _stdscr 
  53.    _kbhit 
  54.    _wgetch 
  55. zodiac{2061}szh: gcc -o foo foo.c -lcurses
  56. collect2: ld returned 2 exit status
  57. ld: Undefined symbol 
  58.    _kbhit 
  59. zodiac{2062}szh: 
  60.  
  61. This just goes to show that if you are going to provide an answer to a
  62. question (that really should not be in this comp.lang.c newsgroup in
  63. the first place), that you should spend some effort to find a complete
  64. answer that is portable. Or certainly qualify your answer precisely!
  65. :-)
  66.  
  67. There *is* a reason that the FAQ talks about this being one of those
  68. non-portable things. See section 19. "System Dependencies" in the FAQ
  69. for more info and please ask these questions (and answer them) in a
  70. newsgroup that is more specific to the system of choice.
  71.  
  72.                                     Z
  73.  
  74.  
  75.  
  76. -- 
  77. -------------------------------------------------------------------------
  78. | Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |
  79. | Z Consulting Group        San Jose, CA 95161             szh@zcon.com |
  80. -------------------------------------------------------------------------
  81.